package com.xzh.service.impl;

import com.xzh.dao.DashboardMapper;
import com.xzh.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class DashboardServiceImpl implements DashboardService {
    private DashboardMapper dashboardMapper;
    @Autowired
    public void setDashboardMapper(DashboardMapper dashboardMapper) {
        this.dashboardMapper = dashboardMapper;
    }
    @Cacheable(value = "dashboardStats", key = "'stats'")
    @Override
    public Map<String, Object> counts() {
        Map<String, Object> stats = new HashMap<>();

        // 获取各项统计数据
        stats.put("students", dashboardMapper.getStudentCount());
        stats.put("courses", dashboardMapper.getCourseCount());
        stats.put("appointments", dashboardMapper.getAppointmentCount());
        stats.put("rating", dashboardMapper.getAverageRating());

        return stats;
    }
}
